package pl.skubicha.utils;

import java.util.ArrayList;
import java.util.List;

import pl.skubicha.domain.PartialGrades;
import pl.skubicha.response.GradesDTO;

public class PartialGradesMapper {
	
	public static GradesDTO map( final PartialGrades grades ) {
		final GradesDTO dto = new GradesDTO();
		dto.setId( grades.getId() );
		dto.setGrade( grades.getGrade() );
		dto.setSubjects( grades.getSubjects() );
		dto.setUsers( grades.getUsers() );
		dto.setForm( grades.getCreditingForm() );
		dto.setDate( grades.getDate() );
		dto.setComment( grades.getComment() );

		return dto;
	}

	public static PartialGrades map( final GradesDTO dto ) {
		final PartialGrades grades = new PartialGrades();
		grades.setId( dto.getId() );
		grades.setGrade( dto.getGrade() );
		grades.setSubjects( dto.getSubjects() );
		grades.setUsers( dto.getUsers() );
		grades.setCreditingForm( dto.getForm() );
		grades.setComment( dto.getComment() );
		grades.setDate( dto.getDate());

		return grades;
	}

	public static List< GradesDTO > map( final Iterable< PartialGrades > grades ) {
		return mapPages( grades );
	}

	private static List< GradesDTO > mapPages( final Iterable< PartialGrades > grades ) {
		final List< GradesDTO > dtos = new ArrayList< GradesDTO >();

		for ( final PartialGrades grade : grades ) {
			dtos.add( map( grade ) );
		}

		return dtos;
	}
}
